from flask import Flask, request, render_template
from spiders.novel import Novel

app = Flask(__name__)

@app.route('/api/sm')#api的说明
def api_sm():
    return render_template('api_sm.html')

@app.route('/api/book_info/')#小说目录信息

def api_book_info():
    '''
    http://127.0.0.1:5000/api/book_info/?url=http://www.x23us.us/39_39642/&host=http://www.x23us.us

    '''
    get_info = request.args

    host = get_info.get('host')
    url = get_info.get('url')

    if host == None or url == None:

        return "请确认你参数"

    result_dict = Novel(host).get_book_info(url)

    # return str(result_dict)

    return result_dict
@app.route('/api/chapter/')#下午作业

def api_chapter_info():#小说网站章节信息接口
    '''
    如下链接，传两参数，返回对应章节信息的json数据格式
    http://127.0.0.1:5000/api/chapter/?url=http://www.x23us.us/39_39642/19553679.html&host=http://www.x23us.us

    '''
    get_info = request.args
    host = get_info.get("host")
    url = get_info.get("url")
    if host == None or url == None:
        return "请检擦你参数"

    result_info = Novel(host).get_chapter_info(url)
    return result_info


@app.route('/api/search/')#小说网站查询接口
def api_search_info():
    '''
    http://127.0.0.1:5000/api/search/?keyworld=大主宰&host=http://www.x23us.us

    '''
    get_info = request.args
    host = get_info.get("host")
    keyword = get_info.get("keyworld")
    if host == None or keyword == None:
        return "请检擦你参数"
    search_info = Novel(host).get_search_info(keyword)
    return search_info






if __name__ == '__main__':
    
    app.run(debug = True)